$(function () {

    var mainPageInfo = '/o2o/frontend/listmainpageinfo';

    $.getJSON(mainPageInfo, function (data) {
        if (data.success) {
            //获取后台参数
            var headLineList = data.headLineList;
            var swiperHtml = '';
            //遍历头条列表,并拼接出轮播图
            headLineList.map(function (item, index) {
                swiperHtml += '<div class="swiper-slide img-wrap">'
                    + '<a href="' + item.lineLink
                    + '" emternal><img class="banner-img" src="' + item.lineImg
                    + '" alter="' + item.lineName + '"></a></div>';
            });
            //拼接内容放入到div 中
            $('.swiper-wrapper').html(swiperHtml);
            //设定轮播图转换时间3秒
            $('.swiper-container').swiper({
                autoplay: 3000,
                //用户对轮播图进行操作时,是否自动停止autoplay
                autoplayDisableOnInteraction: false
            });
            var shopCategoryList = data.shopCategoryList;
            var categoryHtml = '';

            shopCategoryList.map(function (item, index) {
                categoryHtml += '<div class="col-50 shop-classify" data-id='
                    + item.shopCategoryId + '>' + '<div class="word">'
                    + '<p class="shop-title">' + item.shopCategoryName
                    + '</p>' + '<p class="shop-desc">'
                    + item.shopCategoryDesc + '</p>' + '</div>'
                    + '<div class="shop-classify-img-warp">'
                    + '<img class="shop-img" src="' + item.shopCategoryImg
                    + '">' + '</div></div>';
            });

            $('.row').html(categoryHtml);
        }
    });

    //如点击'我的',则显示侧栏
    $('#me').click(function () {
        $.openPanel('#panel-right-demo');
    });

    /**
     * 指定属性绑定单机事件
     */
    $('.row').on('click', 'shop-classify', function (e) {
        var shopCategoryId = e.currentTarget.dataset.id;
        var newUrl = '/o2o/frontend/shoplist?parentId=' + shopCategoryId;
        window.location.href = newUrl;
    });


});